package com.hgkj.cloud.base.scheme.table;

import com.hgkj.cloud.base.scheme.ClsAnswerRequest;
import com.hgkj.cloud.base.scheme.ClsAnswerResult;
import com.hgkj.cloud.base.scheme.ClsScore;

import java.util.Map;

/**
 * 九、爱德华个性偏好测验（Epps）共225题
 */
public class Table9 extends AbstractTable implements TableCalculate{
    String code = "Epps";

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public ClsAnswerResult calc(ClsAnswerRequest answer) {
        return null;
    }

    @Override
    public String[] report(Map map) {
        return new String[0];
    }

    private static ClsAnswerResult GetEppsFactorScore(ClsAnswerRequest answer) {
        ClsAnswerResult result = new ClsAnswerResult();
        result.setMessage("");
        result.setType(answer.getType());
        result.setUuid(answer.getUuid());
        try {
            // 1成就欲，2崇拜欲，3秩序性，4表现欲，5自主性，6亲近性，7探究欲，8求助性，9支配性，10谦卑性，11慈善性，12变导性，13坚毅性，14性爱，15攻击性，16一致性
            // 1正确题数
            int MAX_NUM = 225;

            int intI;
            String[] strAnswer_c = answer.getAnswer().split(g_sChar);
            if (strAnswer_c.length > 1) {
                for (intI = 1; intI < strAnswer_c.length; intI++) {
                    strAnswer_c[intI] = strAnswer_c[intI].trim();
                }
            }

            String[] sAnswer = strAnswer_c[0].toString().split(g_nChar);

            if (sAnswer.length != MAX_NUM) {
                result.setMessage("答案数量不符！");
                return result;
            }

            int i, j, k, l, intLocal;

            // 共2组，第一组0,1；第二组1,0
            // 由公式计算得出
            // 标准分的全部内容(0-28，由于25-28是一致的)
            String[] strStandardA = { "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "1,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0",
                    "2,0,1,0,0,0,0,0,0,0,0,0,0,0,10,0", "3,1,2,0,0,0,0,0,0,0,0,0,0,0,18,0",
                    "4,1,3,1,0,0,1,0,0,0,1,0,1,1,25,0", "5,2,5,2,2,0,2,1,1,1,2,1,2,2,34,0",
                    "6,2,9,3,4,0,3,2,2,2,3,1,3,3,40,0", "7,4,15,6,7,2,5,4,5,3,5,1,6,5,45,1",
                    "8,7,23,9,14,3,9,8,7,5,10,2,10,8,45,1", "9,13,31,14,21,5,13,12,11,9,15,4,15,11,61,5",
                    "10,21,41,18,28,8,19,16,16,15,20,7,23,16,68,9", "11,29,51,27,37,13,29,23,23,20,25,12,30,23,75,13",
                    "12,39,59,36,50,18,39,30,31,29,32,17,38,30,80,18",
                    "13,50,69,45,62,27,49,40,38,39,40,23,47,37,82,26",
                    "14,59,77,55,71,39,60,51,47,47,48,32,56,44,85,34",
                    "15,69,84,64,80,50,66,61,56,56,58,41,63,53,90,46",
                    "16,76,90,73,87,60,75,70,65,65,66,52,70,59,92,56",
                    "17,84,94,79,91,70,82,80,74,71,73,60,78,65,94,65",
                    "18,90,96,85,96,79,89,85,79,79,79,68,83,72,95,76",
                    "19,94,98,89,98,85,94,90,86,86,85,77,87,80,96,83",
                    "20,97,99,94,99,91,95,93,89,91,90,82,91,87,97,89",
                    "21,98,99,95,99,94,97,95,92,95,93,89,94,90,98,94",
                    "22,99,99,98,99,98,99,97,94,97,97,93,96,94,99,97",
                    "23,99,99,99,99,99,99,98,97,99,99,97,98,96,99,99",
                    "24,99,99,99,99,99,99,99,99,99,99,98,99,98,99,99",
                    "25,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99" };
            String[] strSubA;

            // 按标准分得到“指导意见”
            String[] vDoctorIdeaA = new String[16];
            for (i = 0; i < vDoctorIdeaA.length; i++) {
                vDoctorIdeaA[i] = "";
            }
            int[][] vFactorA = new int[16][2]; // 实际为16个因子
            for (i = 0; i < vFactorA.length; i++) {
                for (j = 0; j < vFactorA[1].length; j++) {
                    vFactorA[i][j] = 0;
                }
            }

            // “原始分”
            // 16一致性(先进行，会将某些值清零)
            int[] intNumberA = { 1, 151, 7, 157, 13, 163, 19, 169, 25, 175, 101, 26, 107, 32, 113, 38, 119, 44, 125, 50,
                    201, 51, 207, 57, 213, 63, 219, 69, 225, 75 };
            for (i = 0; i < intNumberA.length; i += 2) {
                if (Integer.valueOf(sAnswer[intNumberA[i] - 1]) != Integer.valueOf(sAnswer[intNumberA[i + 1] - 1])) {
                    vFactorA[15][0] += 1;
                }
                sAnswer[intNumberA[i] - 1] = "0";
            }

            // 前15个因子
            for (i = 0; i < 3; i++) {
                for (j = 0; j < 5; j++) {
                    intLocal = 75 * i + j;
                    for (k = intLocal; k < intLocal + 70 + 1; k += 5) // 第二组
                    {
                        if (Integer.valueOf(sAnswer[k]) == 1) {
                            vFactorA[i * 5 + j][0] += 1;
                        }
                    }
                    for (k = 0; k < 3; k++) {
                        for (l = 0; l < 5; l++) // 第一组
                        {
                            intLocal = 75 * k + l + 5 * (i * 5 + j);
                            if (Integer.valueOf(sAnswer[intLocal]) == 2) {
                                vFactorA[i * 5 + j][0] += 1;
                            }
                        }
                    }

                }
            }

            // “标准分”
            for (i = 0; i < 15; i++) {
                intLocal = vFactorA[i][0] <= 25 ? vFactorA[i][0] : 25;
                strSubA = strStandardA[intLocal].split(",");
                vFactorA[i][1] = Integer.valueOf(strSubA[i + 1]);
            }

            // 按标准分得到“指导意见”
            for (i = 0; i < 15; i++) {
                if (vFactorA[i][1] >= 80) {
                    vDoctorIdeaA[i] = "Epps." + Integer.valueOf(i + 1) + ".1";
                }
            }

            // “一致性”标准分
            // “一致性”指导意见
            vFactorA[15][1] = vFactorA[15][0];
            if (vFactorA[15][1] > 5) {
                vDoctorIdeaA[15] = "Epps.16.1";
            }

            ClsScore.Epps epps = new ClsScore.Epps();
            epps.setCjy_o(vFactorA[0][0]);
            epps.setCjy_s(vFactorA[0][1]);
            epps.setCjy_d(vDoctorIdeaA[0]);

            epps.setCby_o(vFactorA[1][0]);
            epps.setCby_s(vFactorA[1][1]);
            epps.setCby_d(vDoctorIdeaA[1]);

            epps.setCxx_o(vFactorA[2][0]);
            epps.setCxx_s(vFactorA[2][1]);
            epps.setCxx_d(vDoctorIdeaA[2]);

            epps.setBxy_o(vFactorA[3][0]);
            epps.setBxy_s(vFactorA[3][1]);
            epps.setBxy_d(vDoctorIdeaA[3]);

            epps.setZzx_o(vFactorA[4][0]);
            epps.setZzx_s(vFactorA[4][1]);
            epps.setZzx_d(vDoctorIdeaA[4]);

            epps.setQjx_o(vFactorA[5][0]);
            epps.setQjx_s(vFactorA[5][1]);
            epps.setQjx_d(vDoctorIdeaA[5]);

            epps.setTjy_o(vFactorA[6][0]);
            epps.setTjy_s(vFactorA[6][1]);
            epps.setTjy_d(vDoctorIdeaA[6]);

            epps.setQzx_o(vFactorA[7][0]);
            epps.setQzx_s(vFactorA[7][1]);
            epps.setQzx_d(vDoctorIdeaA[7]);

            epps.setZpx_o(vFactorA[8][0]);
            epps.setZpx_s(vFactorA[8][1]);
            epps.setZpx_d(vDoctorIdeaA[8]);

            epps.setQbx_o(vFactorA[9][0]);
            epps.setQbx_s(vFactorA[9][1]);
            epps.setQbx_d(vDoctorIdeaA[9]);

            epps.setCsx_o(vFactorA[10][0]);
            epps.setCsx_s(vFactorA[10][1]);
            epps.setCsx_d(vDoctorIdeaA[10]);

            epps.setByx_o(vFactorA[11][0]);
            epps.setByx_s(vFactorA[11][1]);
            epps.setByx_d(vDoctorIdeaA[11]);

            epps.setJyx_o(vFactorA[12][0]);
            epps.setJyx_s(vFactorA[12][1]);
            epps.setJyx_d(vDoctorIdeaA[12]);

            epps.setXa_o(vFactorA[13][0]);
            epps.setXa_s(vFactorA[13][1]);
            epps.setXa_d(vDoctorIdeaA[13]);

            epps.setGjx_o(vFactorA[14][0]);
            epps.setGjx_s(vFactorA[14][1]);
            epps.setGjx_d(vDoctorIdeaA[14]);

            epps.setYzx_o(vFactorA[15][0]);
            epps.setYzx_d(vDoctorIdeaA[15]);

            result.setObject(epps);
            return result;
        } catch (ArithmeticException e) {
            result.setMessage(e.toString());
            return result;
        }
    }

}
